<?php

//就近 www.jiujin.me
if (!defined('IN_IA')) {
	die('Access Denied');
}
global $_W, $_GPC;
$id = $_GPC['id'];
$openid = m('user')->getOpenid();
$member = m('member')->getInfo($openid);
//套盒二维码 160316
$time = time();
$package = pdo_fetch("SELECT * FROM " . tablename('ewei_shop_package') . " WHERE id = '{$id}' and uniacid = '{$_W['uniacid']}' and status = 1");

if(!empty($package)){
	//扫过的次数
	$all_count = pdo_fetch("SELECT count(*) as count FROM " . tablename('ewei_shop_package_record') . " WHERE package = '{$id}' and uniacid = '{$_W['uniacid']}' and  uid = '{$member['uid']}'");
	if(intval($all_count['count']) < 1 || empty($all_count)){
		$insert = array(
			'uniacid' => $_W['uniacid'],
			'package' => $id,
			'createtime' => time(),
			'uid' => $member['uid'],
			'nickname' => $member['nickname'],
			'goods' => $package['goods'],
			'type' => $package['type'],
			'money' => $package['money']
		);
		pdo_insert('ewei_shop_package_record', $insert);
		if($package['type'] == 2){
			//修改余额
			$credit2 = intval($member['credit2']) + intval($package['money']);
			$data = array('credit2' => $credit2);
			pdo_update('mc_members', $data, array('uniacid' => $_W['uniacid'], 'uid' => $member['uid']));
		}
	}
}
include $this->template('package/list');

